package com.example.mapper;

import com.example.entity.Animal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 操作animal相关数据接口
*/
public interface AnimalMapper {
    void insert(Animal animal);
    //关联查询
    @Select("select animal.*, city.name as cityName from animal left join city on animal.city_id = city.id")
    List<Animal> selectAll();


    @Select("select animal.*, city.name as cityName from animal " +
            "left join city on animal.city_id = city.id " +
            "where animal.name like concat('%',#{name},'%')")
    List<Animal> selectByName(String name);

    void updateById(Animal animal);

    @Delete("delete from animal where id = #{id}")
    void deleteById(Integer id);


    @Select("select * from animal where id = #{id}")
    Animal selectById(Integer animalId);
}